﻿using System;
using System.Collections.Generic;
using System.Linq;
using EzDesk.Apps.Model.Attendance;
using EzDesk.Utility.Web.ViewModels;
using EzDesk.Apps.Interface.Attendance;

namespace EzDesk.Clients.DesktopWeb.Attendance.ViewModel
{
    public class SimpleLeaveInfo : ViewModelBase
    {
        public SimpleLeaveInfo(LeaveInfo leaveInfo, IAttendanceService attendanceService)
        {
            this.Id = leaveInfo.Id;
            this.Start = leaveInfo.StartTime;
            this.End = leaveInfo.EndTime;
            this.Title = leaveInfo.LeaveTypeName;
            this.IsAudited = leaveInfo.IsAudited;
            this.IsAgreed = leaveInfo.IsAgreed;

            this._attendanceService = attendanceService;
        }

        IAttendanceService _attendanceService;

        public Guid Id { get; set; }
        public string Title { get; set; }
        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        public bool IsAudited { get; set; }
        public bool IsAgreed { get; set; }
        public bool IsAllDay
        {
            get
            {
                bool isAllDay = true;
                if (Start.Date == End.Date)
                {
                    var config = _attendanceService.GetAttendanceConfig().Result;
                    if (Start >= config.StdOnDutyTime.ToDateTime(Start)
                        && End <= config.StdOffDutyTime.ToDateTime(End))
                    {
                        isAllDay = false;
                    }
                }
                return isAllDay;
            }
        }
    }
}